const {
    createEnterprise,
    updateEnterprise,
    findOneByUserId,
    deleteEnterprise,
    findByPageEnterprise
} = require("../controller/enterpriseController");
const {validateFunc} = require("../utils/tools");
const {ValidationError} = require("../utils/customError");
// 创建企业
exports.addEnterprise = async (info) => {
    const enterpriseRule = {
        enterpriseType: {
            presence: {
                // 是否为空
                allowEmpty: false
            },
            type: "integer"
        },
        enterpriseName: {
            presence: {
                // 是否为空
                allowEmpty: false
            },
            type: "string"
        },
        address: {
            presence: {
                allowEmpty: false
            },
            type: "string"
        },
        IdFront: {
            presence: {
                // 是否为空
                allowEmpty: false
            },
            type: "string"
        },
        IdBack: {
            presence: {
                // 是否为空
                allowEmpty: false
            },
            type: "string"
        },
        businessLicense: {
            presence: {
                // 是否为空
                allowEmpty: false
            },
            type: "string"
        },
    }
    try {
        await validateFunc(enterpriseRule, info);
        return createEnterprise(info)
    } catch (e) {
        throw new ValidationError("数据验证失败")
    }
}

// 修改企业
exports.editEnterprise = (id, info) => {
    return updateEnterprise(id, info)
}

// 修改企业状态
exports.editEnterpriseStatus = async (id, status) => {
    return updateEnterprise(id, {status})
}


// 删除企业
exports.deleteEnterpriseOne = (id) => {
    return deleteEnterprise(id)
}

// 分页获取企业
exports.getEnterpriseByPage = (query) => {
    return findByPageEnterprise(query)
}

// 判断是否可以发布招募信息
exports.getEnterpriseByUser = async (userId) => {
    return  findOneByUserId(userId);
}
